package com.iceberg.dao.impl.customer;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;

import com.iceberg.dao.customer.CustomerDAO;
import com.iceberg.model.customer.Customer;

public class CustomerDAOImpl implements CustomerDAO {
  private SessionFactory sessionFactory;

  public SessionFactory getSessionFactory() {
    return sessionFactory;
  }

  public void setSessionFactory(SessionFactory sessionFactory) {
    this.sessionFactory = sessionFactory;
  }

  public void addCustomer(Customer customer) {

    SessionFactory sessionFactory = getSessionFactory();

    Session session = sessionFactory.openSession();

    session.save(customer);

  }

  public List<Customer> listCustomer() {

    SessionFactory sessionFactory = getSessionFactory();

    Session session = sessionFactory.openSession();
    @SuppressWarnings("unchecked")
    List<Customer> list = session.createQuery("from Customer").list();
    return list;

  }

}
